const app = getApp()
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');
// pages/home/home.js
Page({
  searchstring:"",
  /**
   * 页面的初始数据
   */
  data: {
    defaultimg: 'http://oss-img.meitianhui.com/test/communityDocs/201801/51a75f1fc3f445cba238b145faff1d41.jpg',
    dianpu: {
      items: []
    },
    sousuo:{
      items:[]
    },
    
    focus:true,

  },



  listClick: function (event) {
    console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" + event);
    var p = event.currentTarget.id
    console.log(event.currentTarget.id);
    wx.navigateTo({ url: '/pages/detail/detail?stores_id=' + p })

  },

  wxSearchfirm: function (e) {
    var that = this
    this.setData({
      searchstring: e.detail.value
    })

    this.searchBtnClick()
  },


  searchBtnClick: function (e) {

    var that = this;
    const data = {
      //测试环境默认设置的
      //门店搜索接口
      page: '{"page_size":"20","page_no":"1"}',
      service: 'member.storeListPageFind',
      params: '{"stores_like":"'+this.data.searchstring+'"}',
      url_type: 'member',
      app_token: app.globalData.app_token,       
      security_code: app.globalData.security_code

    }
    
    const sousuo = this.data.sousuo

    api.requestData({
      data,
      success: (res) => {
        console.log("success 返回 res.data>>>" + res.data);
        var searchData = res.data;
        console.log(searchData);
        console.log(">>>>>>>res.data>>>");
        sousuo.items = searchData.data.list;
        var docList = res.data.data.doc_url
        var doc_url_key = Object.keys(res.data.data.doc_url)
        var itemList = this.data.sousuo.items
        for (var i = 0; i < itemList.length; i++) {

          //console.log(itemList[i])
          //logo_pic_path

          var item_pic_info_str = itemList[i].neighbor_pic_path;
        
          //console.log(item_pic_info_str)
        
            for (var e = 0; e < doc_url_key.length; e++) {
              if (item_pic_info_str === doc_url_key[e]) {
                itemList[i].pic_info = docList[doc_url_key[e]]
                itemList[i].pic_info = itemList[i].pic_info.replace("https", "http")
                console.log(itemList[i].pic_info)
              }
              
            }
        }
        
        this.setData({
          sousuo: sousuo
        })

      },
     
    })


  }
  ,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   //this.search();

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */



  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})